// Created by goerver on 16-7-1.
// bind_add_obj.cpp
#include "AddObj.h"
namespace demo {
    using v8::FunctionCallbackInfo;
    using v8::Isolate;
    using v8::Local;
    using v8::Number;
    using v8::Object;
    using v8::String;
    using v8::Value;

    void CreateObject(const FunctionCallbackInfo<Value>& args) {
        MyObject::NewInstance(args);
    }

    void Add(const FunctionCallbackInfo<Value>& args) {
        Isolate* isolate = args.GetIsolate();

        MyObject* obj1 = node::ObjectWrap::Unwrap<MyObject>(
                args[0]->ToObject());
        MyObject* obj2 = node::ObjectWrap::Unwrap<MyObject>(
                args[1]->ToObject());

        double sum = obj1->value() + obj2->value();
        args.GetReturnValue().Set(Number::New(isolate, sum));
    }

    void InitAll(Local<Object> exports) {
        MyObject::Init(exports->GetIsolate());
        NODE_SET_METHOD(exports, "createObject", CreateObject);
        NODE_SET_METHOD(exports, "add", Add);
    }
    NODE_MODULE(addon, InitAll)
}  // namespace demo